package com.s666.demo.config;

import org.springframework.security.web.authentication.WebAuthenticationDetails;
import javax.servlet.http.HttpServletRequest;

/**
 * @author: 刘宏伟
 * @date: 2018/8/23 17:48
 * @description:
 */
public class CustomWebAuthenticationDetails extends WebAuthenticationDetails {

    private String verifyCode;

    private String targVerifyCode;

    private HttpServletRequest request;

    public CustomWebAuthenticationDetails(HttpServletRequest request) {
        super(request);
        this.verifyCode = request.getParameter("verifyCode");
        this.targVerifyCode = (String)request.getSession().getAttribute("targVerifyCode");
        this.request = request;
    }

    public boolean verify() {
        boolean result = targVerifyCode.equalsIgnoreCase(verifyCode);
        if(result) {
            this.request.getSession().removeAttribute("verifyCode");
        }
        return result;
    }
}
